package com.kx.yooli.kx.wechat.controller.send;

import com.kx.yooli.kx.wechat.po.result.AjaxResult;
import com.kx.yooli.kx.wechat.service.IEmailService;
import jakarta.mail.MessagingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author john_sqwen-childe.wen
 * date 2024/6/2
 * PROJECT_NAME wechat
 * description create MessageSend by john_sqwen
 * and  value is
 */
@RestController
@RequestMapping("/api/message")
public class MessageSend {
    private final Logger log = LoggerFactory.getLogger(MessageSend.class);
    private  final IEmailService iEmailService;

    public MessageSend(IEmailService iEmailService) {
        this.iEmailService = iEmailService;
    }
    @RequestMapping(value = "/send",method = RequestMethod.POST)
    public AjaxResult sendMessage(@RequestParam("mobile") String mobile,@RequestParam("mail")String mail){
        String msg = "";
        try {
            msg = iEmailService.sendAttachmentsMail(mobile,  mail);
        } catch (Exception e) {
            return AjaxResult.error("发送邮件异常，请联系管理员");
        }
        return  AjaxResult.success(msg);
    }
}
